home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
digsby
/
blobs.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
12KB
|
338 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
from __future__ import with_statement
from digsby.abstract_blob import AbstractBlob
import cPickle
from pyxmpp.utils import to_utf8
from copy import deepcopy
from util import Storage
from logging import getLogger
log = getLogger('blobs')
info = log.info
from util.observe import ObservableDict, ObservableList
from struct import pack, unpack
import struct
from os.path import join as pathjoin
from zlib import compress, decompress
import util
import syck
import prefs
from common.notifications import default_notifications
DIGSBY_PREFS_NS = 'digsby:prefs'
DIGSBY_DEFAULT_PREFS_NS = 'digsby:defaultprefs'
DIGSBY_ICON_NS = 'digsby:icon'
DIGSBY_EVENTS_NS = 'digsby:events'
DIGSBY_STATUS_NS = 'digsby:status'
DIGSBY_BUDDYLIST_NS = 'digsby:blist'
DIGSBY_PROFILE_NS = 'digsby:profile'
def to_primitive(thing):
if isinstance(thing, ObservableDict):
return dict(thing)
elif isinstance(thing, ObservableList):
return list(thing)
return thing
def maybe_copy(thing):
if isinstance(thing, (dict, list)):
return deepcopy(thing)
return thing
class NetData(AbstractBlob):
timeout = 300
def pack(cls, data):
return cPickle.dumps(data)
pack = classmethod(pack)
def unpack(cls, data):
return cPickle.loads(data)
unpack = classmethod(unpack)
def set_data(self, data):
try:
return AbstractBlob.set_data(self, self.pack(data))
except:
import sys as sys
print >>sys.stderr, 'Error pickling %r: %s' % (self, repr(data)[:200])
print >>sys.stderr, ' %s' % type(data)
raise
def get_data(self):
try:
retval = self.unpack(AbstractBlob.get_data(self))
return retval
except Exception:
e = None
import traceback as traceback
traceback.print_exc()
log.error('Could not unpickle %s', type(self).__name__)
self.set_data(to_primitive(self.fallback()))
return self.get_data()
def del_data(self):
self._data = None
data = property(get_data, set_data, del_data)
def fallback(self):
return list()
class SerializableNetData(NetData):
__VERSION = 2
def pack(cls, data):
profile = profile
import common
if not profile.blobs3:
d = serialize(data)
d = NetData.pack(d)
d = compress(d)
v = cls._SerializableNetData__VERSION
else:
pydumps = pydumps
import util.json
d = pydumps(data).encode('z')
v = cls._SerializableNetData__VERSION + 1
log.info('packing version %d of %s', v, cls.__name__)
return pack('!I', v) + d
pack = classmethod(pack)
def unpack(cls, data):
(version,) = unpack('!I', data[:4])
if version not in (1, 2, 3):
log.info('unpacking version %d of %s', version, cls.__name__)
data = pack('I', 1) + data
version = 1
if version == 1:
log.info('unpacking version %d of %s', version, cls.__name__)
data = data[4:]
try:
data = data.decode('z')
except Exception:
pass
except:
None<EXCEPTION MATCH>Exception
None<EXCEPTION MATCH>Exception
if version == 2:
log.info('unpacking version %d of %s', version, cls.__name__)
data = data[4:]
data = data.decode('z')
if version != 3:
d = NetData.unpack(data)
if isinstance(d, (SerializedDict, SerializedSet)):
return unserialize(d)
elif isinstance(d, cls.basetype):
return d
else:
return cls.basetype(d)
if version == 3:
log.info('unpacking version %d of %s', version, cls.__name__)
profile = profile
import common
profile = profile()
profile.blobs3 = True
pyloads = pyloads
import util.json
return pyloads(data[4:].decode('z'))
unpack = classmethod(unpack)
class ODictNetData(NetData):
fallback = lambda self: ObservableDict()
basetype = dict
class Prefs(ODictNetData, SerializableNetData):
xml_element_namespace = DIGSBY_PREFS_NS
class DefaultPrefs(NetData):
xml_element_namespace = DIGSBY_DEFAULT_PREFS_NS
diskdata = None
def complete_xml_element(self, xmlnode, _unused):
None if self.tstamp is not None else None
def set_data(self, data):
pass
def get_data(self):
if self.diskdata is None:
defaults = prefs.defaultprefs()
self.diskdata = defaults
return self.diskdata
def del_data(self):
pass
data = property(get_data, set_data, del_data)
class BuddyList(ODictNetData, SerializableNetData):
xml_element_namespace = DIGSBY_BUDDYLIST_NS
class Statuses(SerializableNetData):
xml_element_namespace = DIGSBY_STATUS_NS
fallback = lambda self: ObservableList()
basetype = list
def pack(cls, data):
profile = profile
import common
if not profile.blobs3:
return NetData.pack(data)
else:
return SerializableNetData.pack(data)
pack = classmethod(pack)
class Profile(NetData):
xml_element_namespace = DIGSBY_PROFILE_NS
fallback = lambda self: ''
class Icon(NetData):
xml_element_namespace = DIGSBY_ICON_NS
fallback = lambda self: ''
def pack(cls, data):
return data
pack = classmethod(pack)
def unpack(cls, data):
return data
unpack = classmethod(unpack)
class Notifications(ODictNetData, SerializableNetData):
xml_element_namespace = DIGSBY_EVENTS_NS
fallback = lambda self: deepcopy(default_notifications)
def load_cache_from_data_disk(name, data):
StringIO = StringIO
import StringIO
f = StringIO(data)
try:
plen = struct.unpack('!H', f.read(2))[0]
tstamp = f.read(plen)
data = f.read()
except IOError:
tstamp = '0001-01-01 00:00:00'
data = None
return name_to_obj[name](tstamp, rawdata = data)
def load_cache_from_data_db(name, data):
tstamp = '0001-01-01 00:00:00'
return name_to_obj[name](tstamp, rawdata = data)
class SerializedDict(list):
def __init__(self, dict_):
self[:] = sorted(dict_.iteritems())
class SerializedSet(list):
def __init__(self, set_):
self[:] = sorted(set_)
PrimitiveTypes = frozenset((int, bool, float, long, str, unicode, type(None), type))
def serialize(thing):
t = type(thing)
if t in PrimitiveTypes:
return thing
elif t is tuple:
return tuple((lambda .0: for foo in .0:
serialize(foo))(thing))
elif t is list:
return list((lambda .0: for foo in .0:
serialize(foo))(thing))
elif t is dict:
bar = SerializedDict(thing)
bar[:] = [ serialize(foo) for foo in bar ]
return bar
elif t is set:
bar = SerializedSet(thing)
bar[:] = [ serialize(foo) for foo in bar ]
return bar
def unserialize(thing):
t = type(thing)
if t is SerializedDict:
return dict((lambda .0: for foo in .0:
unserialize(foo))(thing))
elif t is SerializedSet:
return set((lambda .0: for foo in .0:
unserialize(foo))(thing))
elif t is tuple:
return tuple((lambda .0: for foo in .0:
unserialize(foo))(thing))
elif t is list:
return list((lambda .0: for foo in .0:
unserialize(foo))(thing))
elif t in PrimitiveTypes:
return thing
ns_to_obj = {
DIGSBY_PREFS_NS: Prefs,
DIGSBY_ICON_NS: Icon,
DIGSBY_EVENTS_NS: Notifications,
DIGSBY_STATUS_NS: Statuses,
DIGSBY_BUDDYLIST_NS: BuddyList,
DIGSBY_PROFILE_NS: Profile }
name_to_ns = dict((lambda .0: for key, value in .0:
(value.__name__.lower(), key))(ns_to_obj.iteritems()))
name_to_obj = dict((lambda .0: for name in .0:
(name, ns_to_obj[name_to_ns[name]]))(name_to_ns))
from util import dictreverse
ns_to_name = dictreverse(name_to_ns)